const util = require('util');
const path = require('path');

let read = util.promisify(fs.readFile);
read(path.resolve(__dirname, 'age.txt'), 'utf8').then(data => {
  console.log(data);
});

Promise.promisify = function(fn){
  return function(...args){
    return new Promise(function(resolve,reject){
      fn(...args,function(err,data){
        if(err)return reject(err);
        resolve(data);
      });
    });
  };
};

Promise.promisifyAll = function(obj){
  Object.keys(obj).forEach(key=>{
    if(typeof obj[key]==='function'){
      obj[key+'Async'] = Promise.promisify(obj[key]);
    }
  });
};
